<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <table>
        <tr>
            <td colspan="8">简易计算器</td>
        </tr>
        <tr>
            <td>第一个数</td>
            <td><input type="text" id="firstNum"></td>
        </tr>
        <tr>
            <td>第二个数</td>
            <td><input type="text" id="secondNum"></td>
        </tr>
        <tr>
            <td><button onclick="cal('+')">+</button></td>
            <td><button onclick="cal('-')">-</button></td>
            <td><button onclick="cal('*')">*</button></td>
            <td><button onclick="cal('/')">/</button></td>
        </tr>
        <tr>
            <td>计算结果</td>
            <td><input type="text" id="resultId"></td>
        </tr>
    </table>
    <script>

        function cal(type) {
            var num1 = document.getElementById("firstNum").value;
            var num2 = document.getElementById("secondNum").value;
            switch (type) {
                case '+':
                    var result = parseInt(num1) + parseInt(num2);
                    break;
                case '-':
                    var result = parseInt(num1) - parseInt(num2);
                    break;
                case '*':
                    var result = parseInt(num1) * parseInt(num2);
                    break;
                case '/':
                    var result = parseInt(num1) / parseInt(num2);
                    break;
                default:
                    break;
            }
            var resultNum = document.getElementById("resultId");
            resultNum.value = result;

        }

    </script>
</body>

</html>